package cn.kgc.itrip.controller;

import cn.kgc.itrip.beans.dto.Dto;
import cn.kgc.itrip.beans.pojo.User;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;
import springfox.documentation.annotations.ApiIgnore;
import springfox.documentation.spring.web.plugins.Docket;

import java.io.File;
import java.io.IOException;

@RestController
@Api(value = "测试",description = "测试代码",tags = {"222"})
public class TestController {

    @RequestMapping(consumes = "application/json",value = "/addUser",method = RequestMethod.POST)
    @ApiOperation(consumes = "application/json",value = "add用来添加用户",httpMethod = "post",protocols = "https",notes = "笔记",response = Dto.class)
    public Dto addUser(/*@ApiParam(required = true,name = "用户名",value = "用户名2",allowableValues = "最长6位") */
            String id, String name){
        Dto dto = new Dto();
        dto.setCore("10000");
        dto.setMessage("添加成功");
        dto.setData(name+"\t"+id);
        return dto;
    }


    @RequestMapping(consumes = "application/json",value="api/dologin",method = RequestMethod.POST)
    @ApiOperation(consumes = "application/json",value = "addObject接受用户对象",httpMethod = "POST",protocols = "http",notes = "用来注册的方法",response = Dto.class)
    public Dto addObject2(@RequestBody User user){
        System.out.println(user.getId()+"\t"+user.getName()+"\t"+user.getPassword());;
        Dto dto=new Dto();
        dto.setCore("100000");
        System.out.println(user);
        dto.setMessage("用户添加成功");
        dto.setData(user);
        return  dto;
    }




    @RequestMapping(consumes = "application/json",value = "/deleteUser",method = RequestMethod.POST)
    public Dto deleteUser(String id){
        Dto dto = new Dto();
        dto.setCore("20000");
        dto.setMessage("删除成功");
        return dto;
    }


    @ApiIgnore
    @RequestMapping(consumes = "application/json",value="/selectUserById/{id}",method = RequestMethod.GET)
    public Dto selectByid(@PathVariable("id") String id){
        User user=new User();
        user.setId(id);
        user.setName("admin"+id);
        user.setPassword("123456");
        Dto dto=new Dto();
        dto.setCore("100000");
        dto.setMessage("用户查询成功");
        dto.setData(user);
        return  dto;
    }
    @RequestMapping(consumes = "application/json",value = "/uploadFile",method = RequestMethod.POST)
    public Dto upload(User user,@RequestBody MultipartFile upload) throws IOException {
        System.out.println(user);
        System.out.println(upload+"ssss");
        if(!upload.isEmpty()){
            System.out.println(upload+"sssss");
            upload.transferTo(new File("F:/"+upload.getOriginalFilename()));
        }

        Dto dto=new Dto();
        dto.setMessage("上传成功");
        return dto;
    }

}

